package com.affablebeans.model.dal;

import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import com.affablebeans.model.entity.GenericEntity;

/**
 *
 * @author Bora SAYINER
 * @since Jan 25, 2015 6:36:04 PM
 * @version 1.0
 */
public abstract class AbstractDAL<E extends GenericEntity> implements GenericDAL<E> {

	private final DataSource dataSource;

	public AbstractDAL(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	Connection createConnection() throws SQLException {
		return dataSource.getConnection();
	}

	abstract E createEntity(ResultSet resultSet) throws SQLException;

	Date convertToDate(java.util.Date date) {
		return new Date(date.getTime());
	}

}
